<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class LiveOrderList
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "缴纳记录列表ok";
    public $group = '生活缴费';
    public $desc = "";

    public $input = [
        'page_num' => 'int;label=分页;comment=默认为1',
        'page_size' => 'int;label=分页条数;comment=默认为5',
//        'type_id' => 'int;required;label=类型id',
    ];

    public $output = [
        'page_num' => 'label=当前页码;',
        'page_size' => 'label=每页条数;',
        'page_count' => 'label=总条数;',
        'page_total' => 'label=总页数;',
        'list' => [
            [
                'id' => 'label=订单id;',
                'order_no' => 'label=订单号;',
                'buy_num' => 'label=购买数量;',
                'total_money' => 'label=应付金额;',
                'pay_money' => 'label=实付金额;',
                'pay_type' => 'label=支付方式1微信支付 2支付宝支付;',
                'pay_time' => 'label=支付时间;',
                'order_status' => 'label=订单状态0已提交1已支付;',
                'order_type' => 'label=订单类型：0房租缴纳 1物业费缴纳 2水费缴纳 3电费缴纳;',
            ]
        ]
    ];

    public function run($param, $uid)
    {
        $page_num = $param['page_num'] ?: 1;
        $page_size = $param['page_size'] ?: 10;

        $list = (array)M('order')
            ->where([
                'order_status' => 1,
                'order_type' => ['in', '2,3'],
            ])
            ->order('id desc')->page($page_num, $page_size)->select();
        $count = M('order')
            ->where([
                'order_status' => 1,
                'order_type' => ['in', '2,3'],
            ])->count();
        return [
            'list'=> $list,
            'page_count' => $count,
            'page_total' => ceil($count / $page_size)
        ];
    }
}
